/**
 * Created by tanbingqin on 2020/7/29.
 */
import { messages, deepFullCopy } from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import constants from 'share/constants'
import { Button, Form, Switch, Input, Checkbox, Radio, InputNumber, Row, Col, message, Spin, Alert, Tooltip, Icon, Select, Affix, Popover } from 'antd'
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const CheckboxGroup = Checkbox.Group;
const Option = Select.Option;
import formService from 'containers/setting/form/form.service'
import Chooser from 'components/chooser'
import errorMessage from 'share/errorMessage'
import formUtil from 'containers/setting/form/form-util'
import menuRoute from 'routes/menuRoute'

class ExpenseReportProperty extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true,
      disabled: false, //所有表单适用这个属性
      form: {},  //表单信息
      setOfBooksId: '', //表单上的帐套
      priorityValue: {}, //所属组织，启用公司控件value
      priorityRangeValue: {}, //所属组织控件的rangeValue，包含整个对象信息
      paymentTypeList: [], //付款方式下拉列表选择项
      payVisibleScope: 1001, //付款用途选择范围
      paySelectedList: [], //付款用途为部分类型是，选中的现金事务类型
      payDefaultSelectedList: [], //默认的现金事务类型
      contractEnable: false, //是否关联合同
      contractRequired: false, //关联合同时，是否合同必填
      contractLocationList: [], //合同布局位置可选列表
      payDelay: false, //是否启用延迟支付
      isBudgetEr: false, //报销单提交时是否占用预算
      isImportData: false, //报销单是否可导入结算数据
      isMultiLine: false, //差旅，日常，费用报销单是否开启多付款行
      isNotPayeeBring: false, //差旅，日常，费用报销单是否收款方默认不带出
      isNotPayeeEdit: false, //差旅，日常，费用报销单是否收款方默认不允许修改
      addVenMaster: 'false', //差旅，日常，费用报销单和单行，多行借款单，是否允许新增供应商
      createOtherExpense: false, //差旅，日常，费用报销单是否新建他人费用
      withSubsidies: false, //是否添加补贴费用
      withTime: false, //是否启用时间
      newOthersSubsidy: false, //是否添加他人差补
      notShowItinerary: true, //是否不显示大行程
      selectedFormList: [], //补贴费用配置的差旅单
    };
    this.formList = menuRoute.getRouteItem('form-list','key'); //表单列表页
  }

  componentDidMount() {
    this.initPaymentTypeList();
    this.initContactLocation();
    this.initFormData();
    //处理表单属性
    this.initCustomFormPropertyMap();
  };

  initPaymentTypeList = () => {
    //只查询启用的
    formService.getSystemValueList(2105, true).then(resp => {
      let paymentTypeList = [];
      resp.data && resp.data.map(item => {
        paymentTypeList.push({key: item.value, label: item.messageKey});
      });
      this.setState({paymentTypeList, loading: false});
    });
  };

  initContactLocation = () => {
    formService.getContactLocation().then(res => {
      this.setState({contractLocationList: res.data ? res.data : []});
    });
  };

  initFormData = () => {
    const { form } = this.context;
    this.setState({
      form,
      disabled: !form.edit,
      setOfBooksId: form.setOfBooksId
    });
    //处理所属组织，启用公司
    this.initPriorityValue();
    //处理付款用途
    this.initPayUses();
  };

  initCustomFormPropertyMap = () => {
    const { form } = this.context;
    let propertyMap = form.customFormPropertyMap;
    for (let key in propertyMap) {
      if (formUtil.getFieldKey(key, propertyMap[key])) {
        this.props.form.setFieldsValue(formUtil.getFieldKey(key, propertyMap[key]));
      }
      if (formUtil.getStateKey(key, propertyMap[key])) {
        this.setState(formUtil.getStateKey(key, propertyMap[key]));
      }
      if (key === 'report.subsidy.config') {
        let expenseConfig = JSON.parse(propertyMap[key]);
        this.setState({
          withSubsidies: expenseConfig.withSubsidies,
          withTime: expenseConfig.withTime ? expenseConfig.withTime : false,
          notShowItinerary: expenseConfig.notShowItinerary ? expenseConfig.notShowItinerary : false,
          newOthersSubsidy: expenseConfig.newOthersSubsidy ? expenseConfig.newOthersSubsidy : false,
          selectedFormList: expenseConfig.formOID ? [{formOID: expenseConfig.formOID}] : []
        });
      }
    }
  };

  initPriorityValue = () => {
    const { form } = this.context;
    let priorityValue = {
      levelCode: form.fromType === 3 ? "TENANT" : (form.fromType === 2 ? "SET_OF_BOOK" : "COMPANY"),
      levelOrgId: form.fromType === 3 ? this.props.tenant.id : (form.fromType === 2 ? form.setOfBooksId : form.companyOID),
      levelOrgName: form.fromType === 3 ? this.props.tenant.tenantName : (form.fromType === 2 ? form.setOfBooksName : form.companyName)
    };
    if (form.fromType === 2 && form.customFormCompanyRequest.visibleCompanyScope === '2') {
      priorityValue.distribution = {companies: form.customFormCompanyRequest.companyList};
    }
    let priorityRangeValue = {};
    if (form.fromType === 2) {
      priorityRangeValue = {
        setOfBooksId: form.setOfBooksId,
        setOfBooksName: form.setOfBooksName
      }
    }
    if (form.fromType === 1) {
      priorityRangeValue = {
        id: form.companyId,
        companyOID: form.companyOID,
        name: form.companyName,
        setOfBooksId: form.setOfBooksId
      }
    }
    this.setState({priorityValue, priorityRangeValue});
  };

  initPayUses = () => {
    const { form } = this.context;
    let payVisibleScope = form.payUseDTO.visibleScope;
    let paySelectedList = form.payUseDTO.loanTypes || [];
    let payDefaultSelectedList = form.payUseDTO.defaultLoanType ? [form.payUseDTO.defaultLoanType] : [];
    this.setState({payVisibleScope, paySelectedList, payDefaultSelectedList});
  };

  handleStatusChange = (value, key) => {
    const { formOID } = this.context;
    if (key === 'isBudgetCa' || key === 'isBudgetEr') {
      if (formOID && key === 'isBudgetCa') {
        let serviceName = 'getCaFormIsHasData';
        formService[serviceName](formOID).then(res => {
          if (res.data) {
            //有数据时不可更改配置
            message.error(messages('request-2.key21')/*已有相应的业务数据，不可修改。*/);
          } else {
            //没有数据时可更改配置
            this.setState({
              [key]: value
            });
          }
        });
      } else {
        this.setState({
          [key]: value
        });
      }
    } else {
      this.setState({
        [key]: value
      });
    }
  };

  //value为true 说明要刷新列表，为event点击事件时不做刷新
  goBack = (value) => {
    const { close } = this.context;
    if (close) {
      close(value);
    } else {
      this.context.router.push(this.formList.url);
    }
  };

  handleSave = () => {
    const { formOID } = this.context;
    const { refreshBase } = this.props;
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err && this.validateData(values)) {
        let params = this.processValue(values);
        this.setState({loading: true});
        formService.saveNewForm(params).then(res => {
          this.setState({loading: false});
          message.success(messages('common.save.success',{arg1: res.data.formName})/*{arg1} 保存成功*/);
          refreshBase(formOID, 'property');
        }).catch((err) => {
          this.setState({loading: false});
          errorMessage(err.response);
        });
      }
    });
  };

  validateData = (values) => {
    const { formType } = this.context;
    const { payVisibleScope, paySelectedList, payDefaultSelectedList, contractEnable,
      isMultiLine } = this.state;
    // if ((formType === 3001 || formType === 3002 || formType === 3003) && withSubsidies && !selectedFormList.length) {
    //   message.error(messages('request-2.key16')/*请选择差补规则*/);
    //   return false;
    // }
    if (formType === 3001 || formType === 3002 || formType === 3003) {
      if (payVisibleScope === 1002 && !paySelectedList.length) {
        message.error(messages('request-2.key17')/*请选择付款类型*/);
        return false;
      }
      if (!payDefaultSelectedList.length) {
        message.error(messages('request-2.key18')/*请选择付款类型默认值*/);
        return false;
      }
      //付款用途选择部分类型时，默认值需要包含在所选类型中
      if (payVisibleScope === 1002 && !formUtil.isContainDefault(paySelectedList, payDefaultSelectedList[0], 'id')) {
        message.error(messages('request-2.key19')/*默认值需包含于已选择的部分类型*/);
        return false;
      }
      if (contractEnable && !isMultiLine) {
        message.error(messages('request-2.key20')/*关联合同请开启多付款行!*/);
        return false;
      }
    }
    return true;
  };

  processValue = (values) => {
    const { formType, formOID } = this.context;
    const { form, setOfBooksId, priorityValue, priorityRangeValue, userScopeValue, isBudgetCa } = this.state;
    let params = {
      ...form,
      customFormFields: form.customFormFields
    };
    //处理付款用途
    if (formType === 3001 || formType === 3002 || formType === 3003) {
      params.payUseDTO = this.processPayUsesParams();
      if (formOID) {
        params.payUseDTO.entityOID = formOID;
      }
    }
    //处理表单属性
    params.customFormPropertyMap = this.processPropertyMap(values);
    return params;
  };

  //处理付款用途params
  processPayUsesParams = () => {
    const { payVisibleScope, paySelectedList, payDefaultSelectedList } = this.state;
    let params = {};
    params.visibleScope = payVisibleScope;
    params.loanTypeIds = [];
    paySelectedList.map(selected => {
      params.loanTypeIds.push(selected.id);
    });
    params.defaultLoanTypeId = payDefaultSelectedList[0].id;
    return params;
  };

  //处理表单属性
  processPropertyMap = (values) => {
    const { formType } = this.context;
    const { contractEnable, createOtherExpense, isMultiLine, addVenMaster, isBudgetEr, isImportData, withSubsidies,
      withTime, notShowItinerary, selectedFormList, newOthersSubsidy, contractRequired, payDelay, isNotPayeeBring,
      isNotPayeeEdit } = this.state;
    let propertyMap = {};
    //报销单表单属性
    if (formType === 3001 || formType === 3002 || formType === 3003) {
      propertyMap['report.property.create.others.expense'] = createOtherExpense;
      propertyMap['loan.bill.pay.type'] = values.paymentType;
      propertyMap['report.property.associated.contract.enabled'] = contractEnable;
      propertyMap['report.property.associated.contract.config'] = values.contractLocation;
      propertyMap['associate.contract.required'] = contractEnable ? contractRequired : false;
      propertyMap['report.property.pay.multi.lines'] = isMultiLine;
      propertyMap['document.payee.not.bring'] = isNotPayeeBring;
      propertyMap['document.payee.not.changeable'] = isNotPayeeEdit;
      propertyMap['document.venmasteradd.enable'] = addVenMaster;
      propertyMap['report.pay.delay'] = payDelay;
      propertyMap['budget.er.enabled'] = isBudgetEr;
      propertyMap['import.unify.data'] = isImportData;
      let subsidiesConfigValue = {};
      subsidiesConfigValue.withSubsidies = withSubsidies;
      if (withSubsidies) {
        subsidiesConfigValue.withTime = withTime;
        subsidiesConfigValue.notShowItinerary = notShowItinerary;
        subsidiesConfigValue.newOthersSubsidy = newOthersSubsidy;
        if (selectedFormList && selectedFormList.length) {
          subsidiesConfigValue.formOID = selectedFormList[0].formOID;
        }
      }
      propertyMap['report.subsidy.config'] = JSON.stringify(subsidiesConfigValue);
    }
    return propertyMap;
  };

  render() {
    const { formType, formOID } = this.context;
    const { getFieldDecorator, getFieldValue } = this.props.form;
    const { loading, disabled, setOfBooksId, priorityValue, paymentTypeList, isGetPaymentType, payVisibleScope,
      paySelectedList, payDefaultSelectedList, contractEnable, contractRequired, contractLocationList, payDelay,
      isBudgetEr, isMultiLine, isNotPayeeBring, isNotPayeeEdit, addVenMaster, createOtherExpense, withSubsidies,
      withTime, newOthersSubsidy, notShowItinerary, selectedFormList, isImportData } = this.state;
    const formItemLayout = {
      labelCol: {span: 4},
      wrapperCol: {span: 8, offset: 1},
    };
    return (
      <div className="form-new-edit new-form form-detail-base">
        <Spin spinning={loading}>
          <Form>
            {([3001, 3002, 3003].indexOf(formType) > -1) && (
              <FormItem {...formItemLayout} label={messages('request-2.key34')/*付款方式类型*/}>
                {getFieldDecorator('paymentType', {
                  rules: [
                    {
                      required: true,
                      message: messages('common.select')/*请选择*/
                    }
                  ],
                  initialValue: undefined
                })(
                  <Select
                    disabled={disabled}
                    placeholder={messages('common.select')/*请选择*/}
                    defaultActiveFirstOption={false}
                    showArrow={true}
                    getPopupContainer={triggerNode => triggerNode.parentNode}>
                    {paymentTypeList.map((option) => {
                      return <Option key={option.key}>{option.label}</Option>
                    })}
                  </Select>
                )}
              </FormItem>
            )}
            {(formType === 3001 || formType === 3002 || formType === 3003) && (
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key35')/*付款类型*/}>
                  <div style={{marginBottom: '12px'}}>
                    <RadioGroup
                      disabled={disabled}
                      value={payVisibleScope}
                      onChange={e => this.handleStatusChange(e.target.value, 'payVisibleScope')}
                    >
                      <Radio value={1001}>{messages('common.all.type')/*全部类型*/}</Radio>
                      <Radio style={{marginLeft: 50}} value={1002}>{messages('request-2.key9')/*部分类型*/}</Radio>
                    </RadioGroup>
                  </div>
                  {payVisibleScope === 1002 && (
                    <Chooser
                      placeholder={messages('common.select')/*请选择*/}
                      type='payment_cash_type'
                      labelKey='description'
                      valueKey='id'
                      disabled={disabled}
                      onChange={value => this.handleStatusChange(value, 'paySelectedList')}
                      value={paySelectedList}
                      listExtraParams={{
                        filterPaymentTypeConfig: priorityValue.levelCode === 'TENANT',
                        setOfBookId: setOfBooksId, //借款这后台参数定义跟别的不一样，是setOfBookId，而不是setOfBooksId，醉了
                        typeCode: 'PAYMENT' //付款类型
                      }}
                      showNumber={true}
                      single={false}
                    />
                  )}
                  <Row style={{marginTop: 12, marginBottom: 0}} className="normal-width">
                    <Col span={6}>
                      <span style={{fontSize: 14, color: '#f5222d', fontFamily: 'SimSun'}}>*&nbsp;</span> {messages('request-2.key36')/*默认值：*/}
                    </Col>
                    <Col span={18}>
                      <Chooser
                        placeholder={messages('common.select')/*请选择*/}
                        type='payment_cash_type'
                        labelKey='description'
                        valueKey='id'
                        disabled={disabled}
                        onChange={value => this.handleStatusChange(value, 'payDefaultSelectedList')}
                        value={payDefaultSelectedList}
                        listExtraParams={{
                          filterPaymentTypeConfig: priorityValue.levelCode === 'TENANT',
                          setOfBookId: setOfBooksId, //借款这后台参数定义跟别的不一样，是setOfBookId，而不是setOfBooksId，醉了
                          typeCode: 'PAYMENT' //付款类型
                        }}
                        showNumber={false}
                        single={true}
                      />
                    </Col>
                  </Row>
                </FormItem>
              </div>
            )}
            {(formType === 3001 || formType === 3002 || formType === 3003) && (
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key37')/*关联合同*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={contractEnable}
                    onChange={e => this.handleStatusChange(e.target.value, 'contractEnable')}
                  >
                    <Radio value={true}>{messages('request-2.key32')/*关联*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key46')/*不关联*/}</Radio>
                  </RadioGroup>
                </FormItem>
                {contractEnable && (
                  <FormItem {...formItemLayout} label={messages('request-2.key38')/*合同布局位置*/}>
                    {getFieldDecorator('contractLocation', {
                      rules: [
                        {
                          required: true,
                          message: messages('common.select')/*请选择*/
                        }
                      ],
                      initialValue: 'DOCUMENTS_HEAD'
                    })(
                      <Select
                        disabled={disabled}
                        placeholder={messages('common.select')/*请选择*/}
                        defaultActiveFirstOption={false}
                        showArrow={true}
                        getPopupContainer={triggerNode => triggerNode.parentNode}>
                        {contractLocationList.map((option) => {
                          return <Option key={option.code}>{option.name}</Option>
                        })}
                      </Select>
                    )}
                  </FormItem>
                )}
                {contractEnable && (
                  <FormItem {...formItemLayout} label={messages('request-2.key325')/*关联合同必填*/}>
                    <RadioGroup
                      disabled={disabled}
                      value={contractRequired}
                      onChange={e => this.handleStatusChange(e.target.value, 'contractRequired')}
                    >
                      <Radio value={true}>{messages('request-2.key326')/*必填*/}</Radio>
                      <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key327')/*不必填*/}</Radio>
                    </RadioGroup>
                  </FormItem>
                )}
              </div>
            )}
            {(formType === 3001 || formType === 3002 || formType === 3003) &&
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key328')/*延迟支付*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={payDelay}
                    onChange={e => this.handleStatusChange(e.target.value, 'payDelay')}
                  >
                    <Radio value={true}>{messages('request-2.key329')/*开启*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key330')/*不开启*/}</Radio>
                  </RadioGroup>
                  <div style={{color: '#989898'}}>
                    {messages('request-2.key331')/*延迟支付开启后，付款行中收款方类型=供应商时，会显示【延迟支付】字段。用户选择【延迟支付】=是，则该付款行在审核通过后不支付，需发起付款单进行支付。*/}
                  </div>
                </FormItem>
                <FormItem {...formItemLayout} label={messages('request-2.key59')/*提交时占用预算*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={isBudgetEr}
                    onChange={e => this.handleStatusChange(e.target.value, 'isBudgetEr')}
                  >
                    <Radio value={true}>{messages('common.status.enable')/*启用*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key418')/*不启用*/}</Radio>
                  </RadioGroup>
                  <div style={{color: '#989898'}}>
                    {messages('request-2.key419')/*【不启用】预算，后续可改为【启用】预算；*/} <br/>
                    {messages('request-2.key420')/*【启用】预算并产生业务数据后，不可再改为【不启用】。*/}
                  </div>
                </FormItem>
              </div>
            }
            {(formType === 3001 || formType === 3002 || formType === 3003) &&
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key60')/*可导入结算数据*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={isImportData}
                    onChange={e => this.handleStatusChange(e.target.value, 'isImportData')}
                  >
                    <Radio value={true}>{messages('common.import')/*导入*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key334')/*不导入*/}</Radio>
                  </RadioGroup>
                  <div style={{color: '#989898'}}>{messages('request-2.key335')/*选择导入，则报销单详情显示[导入结算数据]按钮，可导入[结算费用]菜单下的数据。*/}</div>
                </FormItem>
              </div>
            }
            {(formType === 3001 || formType === 3002 || formType === 3003) &&
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key336')/*付款行数量*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={isMultiLine}
                    onChange={e => this.handleStatusChange(e.target.value, 'isMultiLine')}
                  >
                    <Radio value={false}>{messages('request-2.key337')/*单付款行*/}</Radio>
                    <Radio value={true} style={{marginLeft: 50}}>{messages('request-2.key62')/*多付款行*/}</Radio>
                  </RadioGroup>
                </FormItem>
                <FormItem {...formItemLayout} label={(
                  <span>{messages('request-2.key338')/*【收款方账号】默认带出*/}&nbsp;
                    <Popover placement="top" content={(
                      <div>
                        <div>{messages('request-2.key339')/*【收款方账号】默认带出逻辑*/}</div>
                        <div style={{color: '#989898', marginTop: 12}}>
                          <div>{messages('request-2.key340')/*报销单付款行中的收款方账号默认带入逻辑，优先级如下：*/}</div>
                          <div>{messages('request-2.key341')/*1、收款方只有1个生效的账号，则默认带出；*/}</div>
                          <div>{messages('request-2.key342')/*2、收款方有2个及以上生效的账号，则默认带出默认账户或主账户*/}</div>
                        </div>
                      </div>
                    )}>
                      <Icon type="info-circle-o" style={{color: '#6C788C'}} />
                    </Popover>
                  </span>
                )}
                >
                  <RadioGroup
                    disabled={disabled}
                    value={isNotPayeeBring}
                    onChange={e => this.handleStatusChange(e.target.value, 'isNotPayeeBring')}
                  >
                    <Radio value={false}>{messages('request-2.key343')/*默认*/}</Radio>
                    <Radio value={true} style={{marginLeft: 50}}>{messages('request-2.key344')/*不默认*/}</Radio>
                  </RadioGroup>
                </FormItem>
                <FormItem {...formItemLayout} label={(
                  <span>{messages('request-2.key345')/*【收款方】允许修改*/}&nbsp;
                    <Popover placement="top" content={(
                      <div>
                        <div>{messages('request-2.key346')/*【收款方】默认逻辑*/}</div>
                        <div style={{color: '#989898', marginTop: 12}}>
                          <div>{messages('request-2.key347')/*报销单付款行中的收款方默认生成逻辑，优先级如下：*/}</div>
                          <div>{messages('request-2.key348')/*1、表单配置「收款方」或「收款单位/个人」，按表头该控件内填写的值生成；*/}</div>
                          <div>{messages('request-2.key349')/*2、表单未配置以上控件，则按费用归属人生成。*/}</div>
                        </div>
                      </div>
                    )}>
                      <Icon type="info-circle-o" style={{color: '#6C788C'}} />
                    </Popover>
                  </span>
                )}
                >
                  <RadioGroup
                    disabled={disabled}
                    value={isNotPayeeEdit}
                    onChange={e => this.handleStatusChange(e.target.value, 'isNotPayeeEdit')}
                  >
                    <Radio value={false}>{messages('request-2.key160')/*允许*/}</Radio>
                    <Radio value={true} style={{marginLeft: 50}}>{messages('request-2.key161')/*不允许*/}</Radio>
                  </RadioGroup>
                </FormItem>
                <FormItem {...formItemLayout} label={messages('request-2.key350')/*员工创建供应商*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={addVenMaster}
                    onChange={e => this.handleStatusChange(e.target.value, 'addVenMaster')}
                  >
                    <Radio style={{marginRight: 50}} value="false">{messages('request-2.key56')/*不可创建*/}</Radio>
                    <Radio style={{marginRight: 50}} value="true">{messages('request-2.key351')/*可创建：供应商+银行账号*/}</Radio>
                    <Radio value="bankOnly">{messages('request-2.key352')/*可创建：银行账号*/}</Radio>
                  </RadioGroup>
                </FormItem>
              </div>
            }
            {(formType === 3001 || formType === 3002 || formType === 3003) &&
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key65')/*新建他人费用*/}>
                  <RadioGroup
                    disabled={disabled}
                    value={createOtherExpense}
                    onChange={e => this.handleStatusChange(e.target.value, 'createOtherExpense')}
                  >
                    <Radio value={true}>{messages('common.yes')/*是*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('common.no')/*否*/}</Radio>
                  </RadioGroup>
                  <div style={{color: '#989898'}}>{messages('request-2.key353')/*可添加人员的范围：报销单单据头参与人控件内人员+报销单申请人。*/}</div>
                </FormItem>
              </div>
            }
            {(formType === 3001 || formType === 3002 || formType === 3003) && (
              <div className="special-height">
                <FormItem {...formItemLayout} label={messages('request-2.key452')/*行程信息*/}>
                  <RadioGroup
                    value={withSubsidies}
                    disabled={disabled}
                    onChange={e => this.handleStatusChange(e.target.value, 'withSubsidies')}
                  >
                    <Radio value={true}>{messages('request-2.key453')/*显示*/}</Radio>
                    <Radio style={{marginLeft: 50}} value={false}>{messages('request-2.key454')/*不显示*/}</Radio>
                  </RadioGroup>
                  {/* 整理 开启行程信息配置项整理成一起*/}
                  {withSubsidies && (<div className="normal-width">
                    <div style={{lineHeight: '31px', marginTop: 12}}>
                      <span style={{color: '#000000', opacity: .85}}>{messages('request-2.key455')/*显示大行程*/}</span>
                    </div>
                    <RadioGroup
                      value={notShowItinerary}
                      disabled={disabled}
                      onChange={e => this.handleStatusChange(e.target.value, 'notShowItinerary')}
                    >
                      <Radio value={true}>{messages('common.no')/*否*/}</Radio>
                      <Radio style={{marginLeft: 50}}
                             value={false}>{messages('common.yes')/*是*/}</Radio>
                    </RadioGroup>

                    <div style={{lineHeight: '31px', marginTop: 12}}>
                      <span style={{
                        color: '#000000',
                        opacity: .85
                      }}>{messages('request-2.key80')/*启用时间*/}</span>
                      <span
                        style={{color: '#989898'}}>&nbsp;&nbsp;&nbsp;{messages('request-2.key456')/*出差往返日期是否启用时间*/}</span>
                    </div>
                    <RadioGroup
                      value={withTime}
                      disabled={disabled}
                      onChange={e => this.handleStatusChange(e.target.value, 'withTime')}
                    >
                      <Radio value={false}>{messages('common.no')/*否*/}</Radio>
                      <Radio style={{marginLeft: 50}}
                             value={true}>{messages('common.yes')/*是*/}</Radio>
                    </RadioGroup>
                    <div style={{lineHeight: '31px', marginTop: 12}}>
                      <span style={{color: '#000000', opacity: .85}}>{messages('request-2.key457')/*添加他人行程*/}</span>
                    </div>
                    <RadioGroup
                      value={newOthersSubsidy}
                      disabled={disabled}
                      onChange={e => this.handleStatusChange(e.target.value, 'newOthersSubsidy')}
                    >
                      <Radio value={false}>{messages('common.no')/*否*/}</Radio>
                      <Radio style={{marginLeft: 50}}
                             value={true}>{messages('common.yes')/*是*/}</Radio>
                    </RadioGroup>
                    <div
                      style={{color: '#989898'}}>{messages('request-2.key353')/*可添加人员的范围：报销单单据头参与人控件内人员+报销单申请人。*/}</div>
                    <div style={{lineHeight: '31px', marginTop: 12}}>
                      <span style={{color: '#000000', opacity: .85}}>{messages('request-2.key458')/*补贴规则*/}</span>
                      <span
                        style={{color: '#989898'}}>&nbsp;&nbsp;&nbsp;{messages('request-2.key459')/*报销单启用补贴费用，则请选择补贴规则；如无需计算补贴，则不选择补贴规则*/}</span>
                    </div>
                    <Chooser
                      placeholder={messages('common.select')/*请选择*/}
                      type='available_travel_rule'
                      labelKey='formName'
                      valueKey='formOID'
                      disabled={disabled}
                      onChange={value => this.handleStatusChange(value, 'selectedFormList')}
                      value={selectedFormList}
                      listExtraParams={{
                        setOfBooksId: priorityValue.levelCode === 'SET_OF_BOOK' ? priorityValue.levelOrgId : null,
                        companyOID: priorityValue.levelCode === 'COMPANY' ? priorityValue.levelOrgId : null,
                      }}
                      showNumber={true}
                      single={true}
                    />
                  </div>)}
                </FormItem>
              </div>
            )}
          </Form>
        </Spin>
        <Affix offsetBottom={0} className="bottom-bar">
          {!disabled && (
            <Button type="primary" loading={loading} onClick={this.handleSave}>{messages('common.ok')/*确定*/}</Button>
          )}
          <Button style={{marginLeft: 15}} onClick={e => this.goBack(true)}>{messages('common.back')/*返回*/}</Button>
        </Affix>
      </div>
    )
  }
}

ExpenseReportProperty.propTypes = {
  refreshBase: React.PropTypes.func
};

function mapStateToProps(state) {
  return {
    tenant: state.login.tenant,
    currentMenuPermission: state.main.currentMenuPermission,
    profile: state.login.profile
  }
}

ExpenseReportProperty.contextTypes = {
  formType: React.PropTypes.any,
  formOID: React.PropTypes.string,
  form: React.PropTypes.object,
  router: React.PropTypes.object,
  close: React.PropTypes.any
};

const WrappedExpenseReportProperty = Form.create()(ExpenseReportProperty);

export default connect(mapStateToProps)(WrappedExpenseReportProperty)
